package com.zzit.vjv.controller;

import com.zzit.vjv.biz.UserBiz;
import com.zzit.vjv.entity.User;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import sun.awt.SunHints;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 用户类控制器
 */
@Controller("userController")
public class UserController {


    @Resource(name = "userBiz")
    private UserBiz userBiz;

    @RequestMapping("/index")
    public String indexUser(Model model,HttpServletRequest request, String name){

        System.out.println("进来");
        List<User> userList=userBiz.findUserList();

        model.addAttribute("userList",userList);

       User user= (User) request.getAttribute("user");


        System.out.println(user+"\n"+model.getAttribute("name"));

        return "index";
    }


    @RequestMapping("/addUser")
    public String addUser(User user ,HttpServletRequest request,Model model) {


        request.setAttribute("user",user);
        model.addAttribute("name","user");

        int row = userBiz.addUser(user);

        if (row > 0) {
            System.out.println("进来1");
           return  "forward:index";

        }



        return "forward:index";
    }


}
